from django.core.paginator import Paginator
from django.db.models import Q
from django.shortcuts import render

# Create your views here.
from app.models import Record


def index_two(request):
    return render(request, 'index3.html', {})


def search_car(request):
    curr_page = int(request.GET.get('page', 1))
    size = int(request.GET.get('size', 5))

    carinfo = request.POST.get('carno', '')
    records = Record.objects.all().select_related('car').order_by('makedate')
    if carinfo:
        records = records.filter(
            Q(car__carno__icontains=carinfo) | Q(car__owner__icontains=carinfo)
        )
    pagination = Paginator(records, size)
    page = pagination.get_page(curr_page)
    res = page
    msg = '没有相关信息！！！'
    return render(request, 'index3.html', locals())
